package com.imti.service.impl;

import com.imti.bean.Registration;
import com.imti.bean.UserInfo;
import com.imti.mapper.RegistrationMapper;
import com.imti.service.RegistrationService;
import com.imti.util.PageBean;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class RegistrationServiceImpl implements RegistrationService {

    @Resource
    private RegistrationMapper registrationMapper;

    @Override
    public PageBean pageRegistrationInfo(Map<String, Object> map) {
        // 1、查询总条数
        Registration registration = (Registration) map.get("registration");
        PageBean pageBean = (PageBean) map.get("page");
        Integer pageLimt = (pageBean.getPage() == null) ? 5 : pageBean.getPage();
        Integer currNum = (pageBean.getCurrNo() == null) ? 1 : pageBean.getCurrNo();
        int totalCount = registrationMapper.getRegistrationCount(registration);
        // 2、查询列表
        PageBean page = new PageBean(pageLimt, currNum);
        map.put("page", page);
        List<Registration> list = registrationMapper.findRegistrationInfo(map);
        // 3、封装pagebean
        PageBean npage = new PageBean(pageLimt, totalCount, currNum, list, "/registration/page", getUserParams(registration));
        return npage;
    }
    private String getUserParams(Registration registration) {
//        StringBuilder sb = new StringBuilder();
//        if (StringUtils.isNotBlank(user.getUserName())) {
//            sb.append("&userName=").append(user.getUserName());
//        }
//        if (StringUtils.isNotBlank(user.getUserState())) {
//            sb.append("&userState=").append(user.getUserState());
//        }
//        if (StringUtils.isNotBlank(user.getStart())) {
//            sb.append("&start=").append(user.getStart());
//        }
//        if (StringUtils.isNotBlank(user.getEnd())) {
//            sb.append("&end=").append(user.getEnd());
//        }
//        return sb.toString();// &userName=34343&userState=1&beginTime=2020-01-03
        return "";
    }
}
